# Alexander F. Gazmararian
# afg2@princeton.edu

# Load packages
library(tidyverse)
library(modelsummary)

source("code/fun/fix_txt.r")

# Load data
g <- readRDS("data/NatCAPS_20220822.rds")

# Load other packages
source("code/fun/coefnames4tables.R")
# Add treatment
coefnames <- c("green_treat"="Treatment: Green Industry", coefnames,
               "Ideo3Conservative"="Ideology: Conservative",
               "Ideo3Liberal"="Ideology: Liberal",
               "climateimport" = "Climate most important (=1)")

# Rename income
g <- rename(g, income = Income_long)

# Estimate models
m <- list()
m[[1]] <- lm(transp_bin ~ green_treat, g)
m[[2]] <- lm(transp_bin ~ green_treat + age + Female + Black + Hispanic + CollegeDegree + income + PartySummary, g)
m[[3]] <- lm(transp_bin ~ green_treat + age + Female + Black + Hispanic + CollegeDegree + income + PartySummary + climateimport, g)
m[[4]] <- lm(transp_bin ~ green_treat + age + Female + Black + Hispanic + CollegeDegree + income + PartySummary + Ideo3 + climateimport, g)

file <- "tables/ch4/ols_greentransp.txt"
modelsummary(
  m,
  v = "HC2",
  stars = c("*"=.1,"**"=.05,"***"=.01),
  coef_map = coefnames,
  gof_map = c("nobs", "adj.r.squared"),
  escape=FALSE,
  output = "latex"
) %>%
  cat(., file = file)
fix_txt(file)
